wx.cloud.init()
var db = wx.cloud.database({
  env: "zousonglin1992-n4jsc"
})
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: [{
        src: "https://46733.s81i.faiusr.com/2/107/AFEIje0CEAIYACD3zNHVBSiAyvDqBTDuBTj8AkBr.jpg"
      },
      {
        src: "https://46733.s81i.faiusr.com/2/107/AFEIje0CEAIYACD2zNHVBSjypZLlBzDuBTj8AkBr.jpg",
      }
    ]
  },
  goTravel(){
    wx.switchTab({
      url: '/pages/travel/travel'
    })
  },
  callPhone() {
    wx.showModal({
      title: '温馨提示',
      content: '拨打电话咨询旅游信息',
      confirmColor: "#F5B223",
      success(res) {
        if (res.confirm) {
          wx.makePhoneCall({
            phoneNumber: "15882354529"
          })
        }
      }
    })
  },
  userVip() {
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo']) {
          wx.navigateTo({
            url: '/pages/login/login'
          })
        } else {
          wx.navigateTo({
            url: '/pages/userVip/userVip'
          })
        }
      }
    })
  },
  goGuoJi(e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    wx.cloud.callFunction({
      name: "getGuojiUrl",
      data: {
        urlId: id
      }
    }).then(res => {
      console.log(res)
      wx.navigateTo({
        url: '/pages/webView/webView?url=' + res.result.data[0].url,
      })
    })
  },
  goGuoNei(e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    wx.cloud.callFunction({
      name: "getGuoneiUrl",
      data: {
        urlId: id
      }
    }).then(res => {
      console.log(res)
      wx.navigateTo({
        url: '/pages/webView/webView?url=' + res.result.data[0].url,
      })
    })
  },
  guoji() {
    var that = this
    db.collection("guoji").get().then(res => {
      console.log(res)
      that.setData({
        guojiData: res.data
      })
    })
  },
  guonei() {
    var that = this
    db.collection("guonei").get().then(res => {
      console.log(res)
      that.setData({
        guoneiData: res.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.guoji()
    this.guonei()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#488fec'
    })
    this.guoji()
    this.guonei()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this
    setTimeout(function () {
      that.guoji()
      that.guonei()
      wx.stopPullDownRefresh()
    }, 1500)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})